package com.ruoyi.jjs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jjs.domain.SaraDept;
import com.ruoyi.jjs.service.ISaraDeptService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 力量列表Controller
 * 
 * @author Allen
 * @date 2022-08-08
 */
@RestController
@RequestMapping("/jjs/dept")
public class SaraDeptController extends BaseController
{
    @Autowired
    private ISaraDeptService saraDeptService;

    /**
     * 查询力量列表列表
     */
    @PreAuthorize("@ss.hasPermi('jjs:dept:list')")
    @GetMapping("/list")
    public AjaxResult list(SaraDept saraDept)
    {
        List<SaraDept> list = saraDeptService.selectSaraDeptList(saraDept);
        return AjaxResult.success(list);
    }

    /**
     * 导出力量列表列表
     */
    @PreAuthorize("@ss.hasPermi('jjs:dept:export')")
    @Log(title = "力量列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SaraDept saraDept)
    {
        List<SaraDept> list = saraDeptService.selectSaraDeptList(saraDept);
        ExcelUtil<SaraDept> util = new ExcelUtil<SaraDept>(SaraDept.class);
        util.exportExcel(response, list, "力量列表数据");
    }

    /**
     * 获取力量列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('jjs:dept:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(saraDeptService.selectSaraDeptByDeptId(deptId));
    }

    /**
     * 新增力量列表
     */
    @PreAuthorize("@ss.hasPermi('jjs:dept:add')")
    @Log(title = "力量列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SaraDept saraDept)
    {
        return toAjax(saraDeptService.insertSaraDept(saraDept));
    }

    /**
     * 修改力量列表
     */
    @PreAuthorize("@ss.hasPermi('jjs:dept:edit')")
    @Log(title = "力量列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SaraDept saraDept)
    {
        return toAjax(saraDeptService.updateSaraDept(saraDept));
    }

    /**
     * 删除力量列表
     */
    @PreAuthorize("@ss.hasPermi('jjs:dept:remove')")
    @Log(title = "力量列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(saraDeptService.deleteSaraDeptByDeptIds(deptIds));
    }
}
